<?php
namespace app\adminbackstage\controller;
/*
 * 资金流水
 */
use think\facade\Request;

use app\adminbackstage\model\Detailed;
/**
 * Description of Index
 *
 * @author asus80
 */
class DetailedController {
    //put your code here
    public function detailedList(){
        
        $page = Request::param('page');
        $num = Request::param('num');

        $start = Request::param('start');
        $end = Request::param('end');
        $phone = Request::param('phone');
        
        $type = Request::param('type');//状态
        $state = Request::param('state');
        
        $u_type = Request::param('u_type');//用户类型
        $remarks = Request::param('remarks');
        $a_id = Request::param('pro_num');//活动编号
        
        $detailed = new Detailed();
        $where = []; 

//        $where[] = ['d.id','>=',5912948];
        $where[] = ['d.uid','>',0];
        //$where[] = ['u.enable','=',1];
        if(!empty($start)){
            $time_start = strtotime($start);
            $where[] = ['d.addtime','>=',$time_start];
        }
        
        if(!empty($end)){
            $time_end = strtotime($end)+(24*3600-1);
            $where[] = ['d.addtime','<',$time_end];
        }
        
        if(!empty($phone)){
            
            $where[] = ['u.phone','=',$phone];
        }
        
        if(!empty($type)){

            $where[] = ['d.type','=',$type];
        }
        
        if(!empty($a_id)){

            $where[] = ['d.a_id','=',$a_id];
        }
        
        if(!empty($u_type)){
            $where[] = ['u.type','=',$u_type];
        }
        
        if(!empty($remarks)){
            $where[] = ['d.remarks','like','%'.$remarks.'%'];
        }

        if(!empty($state)){
            if($state == -1){
                $state = 0;
            }
            $where[] = ['d.state','=',$state];
        }
        $listinfo = $detailed->listDetailed($page,$num,$where);
        $count = $detailed->countDetailed($where); 



//        $cp = ceil($count/$num);//总页数
//
//        $top = '<li><a href="javascript:;" class="pt" title="'.($page-1).'">Prev</a></li>';
//        $tail = '<li><a href="javascript:;" class="pt" title="'.($page+1).'">Next</a></li></ul>';
//
//        if($page == 1){
//            $top = '<li><a href="javascript:;">Prev</a></li>';
//        }
//
//        if($cp == 1){
//            $top = '<li><a href="javascript:;">Prev</a></li>';
//            $tail = '<li><a href="javascript:;">Next</a></li></ul>';
//        }
//
//        if($page == $cp){
//            $tail = '<li><a href="javascript:;">Next</a></li></ul>';
//        }

        foreach ($listinfo as $key => $value) {
            if ($value['type']=='recharge') {
                $listinfo[$key]['type'] = '连连充值';
            }elseif($value['type']=='recharge_hzpay'){
                $listinfo[$key]['type'] = '杭州银行自助充值';
            }elseif($value['type']=='arrears'){
                $listinfo[$key]['type'] = '欠款扣款';
            }elseif($value['type']=='recharge_wxpay'){
                $listinfo[$key]['type'] = '微信充值';
            }elseif($value['type']=='recharge_alipay'){
                $listinfo[$key]['type'] = '支付宝充值';
            }elseif($value['type']=='adapay_alipay'){
                $listinfo[$key]['type'] = '支付宝充值';
            }elseif($value['type']=='adapay_wxpay'){
                $listinfo[$key]['type'] = '微信充值';
            }elseif($value['type']=='phone_wxpay'){
                $listinfo[$key]['type'] = '商家手机端微信充值';
            }elseif($value['type']=='recharge_admin'){
                $listinfo[$key]['type'] = '后台充值';
            }elseif($value['type']=='rebate_admin'){
                $listinfo[$key]['type'] = '后台返利';
            }elseif($value['type']=='after_sales_admin'){
                $listinfo[$key]['type'] = '后台售后';
            }elseif($value['type']=='deduct_admin_arrears'){
                $listinfo[$key]['type'] = '后台扣款,余额不足,欠款';
            }elseif($value['type']=='deduct_admin'){
                $listinfo[$key]['type'] = '后台扣款';
            }elseif($value['type']=='withdrawal_freeze'){
                $listinfo[$key]['type'] = '提现冻结';
            }elseif($value['type']=='withdrawal_success'){
                $listinfo[$key]['type'] = '提现成功';
            }elseif($value['type']=='withdrawal_fee'){
                $listinfo[$key]['type'] = '提现成功 -- 扣除手续费';
            }elseif($value['type']=='withdrawal_unfreeze'){
                $listinfo[$key]['type'] = '提现失败 解冻';
            }elseif($value['type']=='shop_pay'){
                $listinfo[$key]['type'] = '购买店铺支出';
            }elseif($value['type']=='activity_commission_freeze'){
                $listinfo[$key]['type'] = '活动发布冻结 -- 冻结佣金';
            }elseif($value['type']=='order_wxpay'){
                $listinfo[$key]['type'] = '样品订单-微信支付';
            }elseif($value['type']=='sample_order_balance_wxpay'){
                $listinfo[$key]['type'] = '样品订单-余额支付';
            }else{
                $listinfo[$key]['type'] = '其他';
            }
            /*elseif($value['type']=='arrears'){
                $listinfo[$key]['type'] = '扣款-抵扣负债';
            }
            elseif($value['type']=='recharge_wxpay'){
                $listinfo[$key]['type'] = '微信充值';
            }
            elseif($value['type']=='recharge_alipay'){
                $listinfo[$key]['type'] = '支付宝充值';
            }
            elseif($value['type']=='withdrawal_freeze'){
                $listinfo[$key]['type'] = '提现冻结';
            }
            elseif($value['type']=='withdrawal_success'){
                $listinfo[$key]['type'] = '提现成功';
            }
            elseif($value['type']=='withdrawal_fee'){
                $listinfo[$key]['type'] = '提现成功手续费扣除';
            }
            elseif($value['type']=='withdrawal_unfreeze'){
                $listinfo[$key]['type'] = '提现失败';
            }
            elseif($value['type']=='shop_pay'){
                $listinfo[$key]['type'] = '购买店铺支出';
            }
            elseif($value['type']=='member_open_pay'){
                $listinfo[$key]['type'] = '开通会员';
            }
            elseif($value['type']=='member_renew_pay'){
                $listinfo[$key]['type'] = '续费会员';
            }
            elseif($value['type']=='member_up_pay'){
                $listinfo[$key]['type'] = '升级会员';
            }
            elseif($value['type']=='activity_rebate_freeze'){
                $listinfo[$key]['type'] = '活动发布冻结返利金';
            }
            elseif($value['type']=='activity_bond_freeze'){
                $listinfo[$key]['type'] = '活动发布冻结保证金';
            }
            elseif($value['type']=='activity_commission_freeze'){
                $listinfo[$key]['type'] = '活动发布冻结佣金';
            }
            elseif($value['type']=='activity_commission_freeze'){
                $listinfo[$key]['type'] = '活动发布冻结佣金';
            }
            elseif($value['type']=='activity_increment_freeze'){
                $listinfo[$key]['type'] = '活动发布冻结增值服务费';
            }
            elseif($value['type']=='activity_append_rebate_freeze'){
                $listinfo[$key]['type'] = '活动追加冻结返利金';
            }
            elseif($value['type']=='activity_append_bond_freeze'){
                $listinfo[$key]['type'] = '活动追加冻结保证金';
            }
            elseif($value['type']=='activity_append_commission_freeze'){
                $listinfo[$key]['type'] = '活动追加冻结返佣金';
            }
            elseif($value['type']=='activity_append_increment_freeze'){
                $listinfo[$key]['type'] = '活动追加冻结返增值服务费';
            }
            elseif($value['type']=='activity_audit_false_rebate_unfreeze'){
                $listinfo[$key]['type'] = '审核未通过退回返利金';
            }
            elseif($value['type']=='activity_audit_false_bond_unfreeze'){
                $listinfo[$key]['type'] = '审核未通过退回保证金';
            }
            elseif($value['type']=='activity_audit_false_commission_unfreeze'){
                $listinfo[$key]['type'] = '审核未通过退回佣金';
            }
            elseif($value['type']=='activity_audit_false_increment_unfreeze'){
                $listinfo[$key]['type'] = '审核未通过退回增值服务费';
            }
            elseif($value['type']=='activity_rebate_unfreeze'){
                $listinfo[$key]['type'] = '未售出份数退回返利金';
            }
            elseif($value['type']=='activity_bond_unfreeze'){
                $listinfo[$key]['type'] = '结算退回保证金';
            }
            elseif($value['type']=='activity_commission_pay'){
                $listinfo[$key]['type'] = '售出份数佣金支付';
            }
            elseif($value['type']=='activity_commission_unfreeze'){
                $listinfo[$key]['type'] = '未售出份数退回佣金';
            }
            elseif($value['type']=='activity_increment_unfreeze'){
                $listinfo[$key]['type'] = '未售出份数退回增值服务费';
            }
            elseif($value['type']=='order_freeze'){
                $listinfo[$key]['type'] = '冻结-订单返利金';
            }
            elseif($value['type']=='activity_rebate_pay'){
                $listinfo[$key]['type'] = '子订单审核通过扣除返利金';
            }
            elseif($value['type']=='activity_rebate_refund'){
                $listinfo[$key]['type'] = '子订单返利金差价退回';
            }
            elseif($value['type']=='activity_increment_pay'){
                $listinfo[$key]['type'] = '子订单审核通过扣除增值服务费';
            }
            elseif($value['type']=='order_unfreeze'){
                $listinfo[$key]['type'] = '解冻-订单返利金';
            }
            elseif($value['type']=='order_gold_unfreeze'){
                $listinfo[$key]['type'] = '订单石榴籽抵扣到账';
            }
            elseif($value['type']=='order_complain_return'){
                $listinfo[$key]['type'] = '子订单售后成功';
            }
            elseif($value['type']=='order_complain_refund'){
                $listinfo[$key]['type'] = '子订单售后返还';
            }
            elseif($value['type']=='order_complain_debt_refund'){
                $listinfo[$key]['type'] = '子订单售后返还可用余额不足,欠款';
            }
            elseif($value['type']=='order_complain_freeze_refund'){
                $listinfo[$key]['type'] = '子订单售后,冻结返利金扣除';
            }
            elseif($value['type']=='one_sale_commission'){
                $listinfo[$key]['type'] = '一级粉丝下单返利';
            }
            elseif($value['type']=='two_sale_commission'){
                $listinfo[$key]['type'] = '二级粉丝下单返利';
            }
            elseif($value['type']=='one_open_member_sale_commission'){
                $listinfo[$key]['type'] = '一级粉丝购买会员返利';
            }
            elseif($value['type']=='two_open_member_sale_commission'){
                $listinfo[$key]['type'] = '二级粉丝购买会员返利';
            }
            elseif($value['type']=='order_complain_merchant_deduct'){
                $listinfo[$key]['type'] = '订单售后支付差价补足';
            }
            elseif($value['type']=='order_complain_merchant_deduct_debt'){
                $listinfo[$key]['type'] = '订单售后支付差价补足,余额不足[欠款]';
            }
            elseif($value['type']=='order_complain_merchant_user'){
                $listinfo[$key]['type'] = '订单商家补发返利金';
            }
            elseif($value['type']=='order_complain_merchant_user_freeze'){
                $listinfo[$key]['type'] = '冻结-订单商家补发返利金';
            }
            elseif($value['type']=='order_complain_user_deduct'){
                $listinfo[$key]['type'] = '订单退回多发返利金';
            }
            elseif($value['type']=='order_complain_user_deduct_debt'){
                $listinfo[$key]['type'] = '订单退回多发返利金,余额不足[欠款]';
            }
            elseif($value['type']=='order_complain_user_deduct_freeze'){
                $listinfo[$key]['type'] = '冻结-订单退回多发返利金';
            }
            elseif($value['type']=='order_complain_user_deduct_freeze'){
                $listinfo[$key]['type'] = '冻结-订单退回多发返利金';
            }
            elseif($value['type']=='order_complain_user_merchant'){
                $listinfo[$key]['type'] = '订单返利金差价退回';
            }
            elseif($value['type']=='order_complain_all_user_merchant_gold'){
                $listinfo[$key]['type'] = '订单退回多发返利金,石榴籽返利退回,石榴籽返还';
            }
            elseif($value['type']=='order_complain_all_user_merchant_gold_debt'){
                $listinfo[$key]['type'] = '订单退回多发返利金,石榴籽返利退回,余额不足,石榴籽返还';
            }
            elseif($value['type']=='merchant_extension_open_member_award'){
                $listinfo[$key]['type'] = '被邀请商家开通会员';
            }*/

            
            if ($value['state']==1) {
                $listinfo[$key]['state_str'] = '收入';
            }
            elseif($value['state']==2){
                $listinfo[$key]['state_str'] = '支出';
            }
            elseif ($value['state']==3) {
                $listinfo[$key]['state_str'] = '冻结';
            }
            elseif ($value['state']==4) {
                $listinfo[$key]['state_str'] = '解冻';
            }
            elseif ($value['state']==0) {
                $listinfo[$key]['state_str'] = '不变';
            }
            
            /*if($value['u_type'] == 2){
                $listinfo[$key]['u_type'] = '商家用户';
            }
            else{
                $listinfo[$key]['u_type'] = '买家用户';
            }*/
            
            $listinfo[$key]['time'] = date( "Y-m-d H:i:s",$value['addtime']); 
            $listinfo[$key]['addtime'] = date( "Y-m-d H:i:s",$value['addtime']); 
        }
        
//        $list = '<ul>'.$top.$tail.'</ul>';
//        $return = array($listinfo,$list);
//        
//        echo json_encode($return);
        return json(['code' => 1, 'msg' => lang(''), 'data' => $listinfo, 'count' => $count]);
    }
}
